<?php
//require_once('class.detail.php');

class BuatPdf {

	public function createSurat($details){
		require_once('../tcpdf/config/lang/eng.php');
        require_once('../tcpdf/tcpdf.php');
        

        $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>Untitled Document</title>
			<style>
				p {
					margin-top:30px;
			        margin-bottom:20px;
				}
			</style>
			</head>
			<body>
			<table width="500" border="0">
			  <tr>
			    <td width="100" style="text-align:center;"><img src="../img/depkeu.jpeg" /></td>
			    <td width="400" style="text-align:center;">
			    	<table>
			    		<tr>
							<td></td>
						</tr>
			    		<tr>
							<td>KEMENTERIAN KEUANGAN REPUBLIK INDONESIA</td>
						</tr>
						<tr>
							<td>DIREKTORAT JENDERAL PERBENDAHARAAN</td>
						</tr>
						<tr>
							<td>GEDUNG PRIJADI PRAPTOSUHARJO I LANTAI II</td>
						</tr>
						<tr>
							<td>JALAN LAPANGAN BANTENG TIMUR NO 2-4 JAKARTA PUSAT</td>
						</tr>
						<tr>
							<td>TELEPON (021) 3449230 (20 SALURAN)</td>
						</tr>
						<tr>
							<td>SITUS www.perbendaharaan.go.id</td>
						</tr>
			    	</table>
			    </td>
			  </tr>
			</table>
			<hr />
			<table>
				<tr>
					<td colspan="3"></td>
				</tr>
				<tr>
					<td width="70">Nomor&nbsp; :</td>
					<td width="320">S-  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    /PB/2013</td>
					<td>Jakarta, 10 September 2013</td>
				</tr>
				<tr>
					<td width="70">Sifat &nbsp;&nbsp;&nbsp;&nbsp;:</td>
					<td>Segera</td>
					<td></td>
				</tr>
				<tr>
					<td width="70">Lamp. &nbsp;:</td>
					<td>Satu Berkas</td>
					<td></td>
				</tr>
				<tr>
					<td width="70">Hal &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>
					<td colspan="2">Ijin Melakukan Perjalanan Ke Luar Negeri Tahun '.date('Y').'</td>					
				</tr>
			</table>
			<br />
			<table>
				<tr>
					<td width="70"></td>
				</tr>
				<tr>
					<td width="70">Yth. Menteri Keuangan RI</td>
				</tr>
				<tr>
					<td width="170">up. Sekretaris Jenderal Kementerian Keuangan RI</td>
				</tr>
				<tr>
					<td width="70">Jakarta</td>
				</tr>
				<tr>
					<td width="70"></td>
				</tr>
			</table>
			<table width="540" border="0">
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:1.5em;">Sesuai Peraturan Pemerintah RI Nomer 24 Tahun 1976 serta Keputusan Menteri Keuangan
				  		Nomor 351/KMK.01/2009 tanggal 8 September 2009, dengan ini disampaikan permohonan 
				  		ijin melakukan perjalanan ke luar negeri untuk keperluan pribadi atau diluar kedinasan pegawai atas nama :</p></td>
				  </tr>
			</table>
			<table width="560" border="1">
				<tr style="background-color=grey;">
					<td width="35" style="text-align:center;">No</td>
					<td width="125" style="text-align:center;">Nama, NIP dan Golongan</td>
					<td width="125" style="ext-align:center;">Jabatan / Unit Kerja</td>
					<td width="95" style="text-align:center;">Tanggal Pelaksanaan</td>
					<td width="75" style="text-align:center;">Cuti Yang Digunakan</td>
					<td width="80" style="text-align:center;">Keterangan</td>
				</tr>';

			for($i=0;$i<count($details);$i++){
				//for($y=0;$y<count($details[$i]);$y++){
					$html.='<tr>';
					$html.='<td width="35" style="text-align:center;">'.($i+1).'</td>';
					$html.='<td width="125" style="text-align:center;">'.$details[$i]['nama'].' '.$details[$i]['nip'].' '.$details[$i]['golongan'].'</td>';
					$str=ucwords(strtolower($details[$i]['eselon']));
					$html.='<td width="125" style="text-align:center;">'.$str.'</td>';
					$html.='<td width="95" style="text-align:center;">'.$details[$i]['tgl_mulai'].' s.d. '.$details[$i]['tgl_selesai'].'</td>';
					$html.='<td width="75" style="text-align:center;">'.$details[$i]['id_cuti'].'</td>';
					$html.='<td width="80" style="text-align:center;">'.$details[$i]['id_tujuan'].'</td>';
					$html.='</tr>';
				//}
			}



			$html.='</table><table width="540" border="0">
				<tr><td></td></tr>
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:1.5em;">Berkenaan dengan hal tersebut di atas, dimohon kiranya surat ijin ke luar negeri
				    pegawai tersebut dapat ditetapkan.</p></td>
				  </tr>
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:1.5em;">Demikian disampaikan atas perhatiannya diucapkan terima kasih.</p></td>
				  </tr>
			</table>
			<table width="560" border="0">
					<tr>
				    <td style="text-align:center; line-height:1em; text-indent: 2px;"></td>
				    <td style="text-align:center; line-height:1em;"></td>
				  </tr>
				  <tr>
				    <td style="text-align:center; line-height:1em; text-indent: 2px;"></td>
				    <td style="text-align:center; line-height:1em;">a.n. Direktur Jenderal Perbendaharaan</td>
				  </tr>
				  <tr>
				    <td style="text-align:center; line-height:1em; text-indent: 25px;"></td>
				    <td style="text-align:center; line-height:1em;">Sekretaris Direktorat Jenderal</td>
				  </tr>
				  <tr>
				    <td style="line-height:3.2em;">&nbsp;</td>
				    <td style="line-height:3.2em;">&nbsp;</td>
				  </tr>
				  <tr>
				    <td style="line-height:1em; text-indent: 65px;"></td>
				    <td style="line-height:1em; text-indent: 65px;">Tata Suntara</td>
				  </tr>
				  <tr>
				    <td style="line-height:1em; text-indent: 65px;"></td>
				    <td style="line-height:1em; text-indent: 65px;">NIP. 195401151975121001</td>
				  </tr>
				</table>
			</body>
			</html>
			';
		$pdf = new TCPDF('P', 'mm', 'F4', true, 'UTF-8', false);

        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Eko Sigit / 5210105007');
        $pdf->SetTitle('Pengajuan Ijin Luar Negeri');
        $pdf->SetSubject('Ijin Luar Negeri');
        $pdf->SetKeywords('ijin, luar, negeri');


        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
        $pdf->SetMargins('4', '1', '2');
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
        //$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
        //$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
        $pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set default font subsetting mode
        $pdf->setFontSubsetting(true);

        $pdf->SetFont('helvetica', '', 11, '', true);

// Add a page 
// This method has several options, check the source code documentation for more information.
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->AddPage();

//*************
        ob_end_clean();
//************* 
        $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'left', $autopadding = false);

        $pdf->Output('../dokumen/suratpdf.pdf', 'F');
        echo json_encode('dokumen/suratpdf.pdf');

	}


	public function createSuratDoc($details){
		include("html_to_doc.inc.php");
        $htmltodoc= new HTML_TO_DOC(); 

        $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>Untitled Document</title>
			<style>
				p {
					margin-top:30px;
			        margin-bottom:20px;
				}
			</style>
			</head>
			<body>
			<table width="650" border="0">
			  <tr>
			    <td width="100" style="text-align:center;"><img src="../img/depkeu.jpeg" /></td>
			    <td width="550" style="text-align:center;">
			    	<table>
			    		<tr>
							<td></td>
						</tr>
			    		<tr>
							<td>KEMENTERIAN KEUANGAN REPUBLIK INDONESIA</td>
						</tr>
						<tr>
							<td>DIREKTORAT JENDERAL PERBENDAHARAAN</td>
						</tr>
						<tr>
							<td>GEDUNG PRIJADI PRAPTOSUHARJO I LANTAI II</td>
						</tr>
						<tr>
							<td>JALAN LAPANGAN BANTENG TIMUR NO 2-4 JAKARTA PUSAT</td>
						</tr>
						<tr>
							<td>TELEPON (021) 3449230 (20 SALURAN)</td>
						</tr>
						<tr>
							<td>SITUS www.perbendaharaan.go.id</td>
						</tr>
			    	</table>
			    </td>
			  </tr>
			</table>
			<hr />
			<table>
				<tr>
					<td colspan="3"></td>
				</tr>
				<tr>
					<td width="70">Nomor&nbsp; :</td>
					<td width="370">S-  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    /PB/2013</td>
					<td>Jakarta, 10 September 2013</td>
				</tr>
				<tr>
					<td width="70">Sifat &nbsp;&nbsp;&nbsp;&nbsp;:</td>
					<td>Segera</td>
					<td></td>
				</tr>
				<tr>
					<td width="70">Lamp. &nbsp;:</td>
					<td>Satu Berkas</td>
					<td></td>
				</tr>
				<tr>
					<td width="70">Hal &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>
					<td colspan="2">Ijin Melakukan Perjalanan Ke Luar Negeri Tahun '.date('Y').'</td>					
				</tr>
			</table>
			<br />
			<table>
				<tr>
					<td width="70"></td>
				</tr>
				<tr>
					<td width="170">Yth. Menteri Keuangan RI</td>
				</tr>
				<tr>
					<td width="370">up. Sekretaris Jenderal Kementerian Keuangan RI</td>
				</tr>
				<tr>
					<td width="170">Jakarta</td>
				</tr>
				<tr>
					<td width="170"></td>
				</tr>
			</table>
			<table width="620" border="0">
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:0.1em;">Sesuai Peraturan Pemerintah RI Nomer 24 Tahun 1976 serta Keputusan Menteri Keuangan
				  		Nomor 351/KMK.01/2009 tanggal 8 September 2009, dengan ini disampaikan permohonan 
				  		ijin melakukan perjalanan ke luar negeri untuk keperluan pribadi atau diluar kedinasan pegawai atas nama :</p></td>
				  </tr>
			</table>
			<table width="620" style="border: 1px solid black; border-style: inset; border-collapse: collapse;">
				<tr style="background-color=grey;">
					<td width="35" style="text-align:center; border: 1px solid black;">No</td>
					<td width="125" style="text-align:center; border: 1px solid black;">Nama, NIP dan Golongan</td>
					<td width="125" style="ext-align:center; border: 1px solid black;">Jabatan / Unit Kerja</td>
					<td width="95" style="text-align:center; border: 1px solid black;">Tanggal Pelaksanaan</td>
					<td width="75" style="text-align:center; border: 1px solid black;">Cuti Yang Digunakan</td>
					<td width="80" style="text-align:center; border: 1px solid black;">Keterangan</td>
				</tr>';

			for($i=0;$i<count($details);$i++){
				//for($y=0;$y<count($details[$i]);$y++){
					$html.='<tr>';
					$html.='<td width="35" style="text-align:center; border: 1px solid black;">'.($i+1).'</td>';
					$html.='<td width="125" style="text-align:center; border: 1px solid black;">'.$details[$i]['nama'].' '.$details[$i]['nip'].' '.$details[$i]['golongan'].'</td>';
					$str=ucwords(strtolower($details[$i]['eselon']));
					$html.='<td width="125" style="text-align:center; border: 1px solid black;">'.$str.'</td>';
					$html.='<td width="95" style="text-align:center; border: 1px solid black;">'.$details[$i]['tgl_mulai'].' s.d. '.$details[$i]['tgl_selesai'].'</td>';
					$html.='<td width="75" style="text-align:center; border: 1px solid black;">'.$details[$i]['id_cuti'].'</td>';
					$html.='<td width="80" style="text-align:center; border: 1px solid black;">'.$details[$i]['id_tujuan'].'</td>';
					$html.='</tr>';
				//}
			}



			$html.='</table><table width="620" border="0" padding="0">
				<tr><td></td></tr>
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:0.1em;">Berkenaan dengan hal tersebut di atas, dimohon kiranya surat ijin ke luar negeri
				    pegawai tersebut dapat ditetapkan.</p></td>
				  </tr>
				  <tr>
				    <td><p style="text-indent:25px; text-align:justify; line-height:0.1em;">Demikian disampaikan atas perhatiannya diucapkan terima kasih.</p></td>
				  </tr>
			</table>
			<table width="620" border="0">
					<tr>
				    <td style="text-align:center; line-height:1em; text-indent: 2px;"></td>
				    <td style="text-align:center; line-height:1em;"></td>
				  </tr>
				  <tr>
				    <td style="text-align:center; line-height:1em; text-indent: 2px;"></td>
				    <td style="text-indent: 325px; line-height:1em;">a.n. Direktur Jenderal Perbendaharaan</td>
				  </tr>
				  <tr>
				    <td style="text-align:center; line-height:1em; text-indent: 25px;"></td>
				    <td style="text-indent: 355px; line-height:1em;">Sekretaris Direktorat Jenderal</td>
				  </tr>
				  <tr>
				    <td style="line-height:3.2em;">&nbsp;</td>
				    <td style="line-height:3.2em;">&nbsp;</td>
				  </tr>
				  <tr>
				    <td style="line-height:1em; text-indent: 65px;"></td>
				    <td style="line-height:1em; text-indent: 355px;">Tata Suntara</td>
				  </tr>
				  <tr>
				    <td style="line-height:1em; text-indent: 65px;"></td>
				    <td style="line-height:1em; text-indent: 355px;">NIP. 195401151975121001</td>
				  </tr>
				</table>
			</body>
			</html>
			';

		
		//$docx->addTemplate('../word_documents/myTestTemplate.docx');
		$htmltodoc->createDoc($html,"../dokumen/surat"); 
        echo json_encode('dokumen/surat.doc');

	}

	public function cetakXls($data){
		require_once('../phpexcel/PHPExcel.php');

		$objPHPExcel = new PHPExcel();

		$objPHPExcel->getProperties()->setCreator("Eko SigitP")
	      ->setLastModifiedBy("Eko SigitP")
	      ->setTitle("Office 2007 XLSX Test Document")
	      ->setSubject("Office 2007 XLSX Test Document")
	      ->setDescription("Daftar Pegawai Ijin LN .")
	      ->setKeywords("office 2007 openxml php")
	      ->setCategory("UMR 2013");

	    $objPHPExcel->setActiveSheetIndex(0)
	       ->setCellValue('A1', 'NIP')
	       ->setCellValue('B1', 'Nama')
	       ->setCellValue('C1', 'Golongan')
	       ->setCellValue('D1', 'Jabatan')
	       ->setCellValue('E1', 'Tanggal Cuti')
	       ->setCellValue('F1', 'Jenis Cuti')
	       ->setCellValue('G1', 'Keterangan');

	    $baris = 2;
	    for($i=0;$i<count($data);$i++){
	    	$objPHPExcel->setActiveSheetIndex(0)
		     	->setCellValue('A'.$baris, '\''.$data[$i]['nip'])
		        ->setCellValue('B'.$baris, $data[$i]['nama'])
		        ->setCellValue('C'.$baris, $data[$i]['golongan'].' / '.$data[$i]['pangkat'])
		        ->setCellValue('D'.$baris, $data[$i]['eselon'])
		        ->setCellValue('E'.$baris, $data[$i]['tgl_mulai']." s.d. ".$data[$i]['tgl_selesai'] )
		        ->setCellValue('F'.$baris, $data[$i]['id_cuti'])
		        ->setCellValue('G'.$baris, $data[$i]['id_tujuan']);
			$baris++;
	    }

	    $objPHPExcel->getActiveSheet()->setTitle('transaksi');
  
		$objPHPExcel->setActiveSheetIndex(0);

		// header('Content-Type: application/vnd.ms-excel');
		// header('Content-Disposition: attachment;filename="dokumen/ijinLN.xls"');
		// header('Cache-Control: max-age=0');
		  
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('../dokumen/ijinLN.xls');
		echo json_encode('dokumen/ijinLN.xls');
		//exit;

	}
}


?>